package com.hehe.controller;

import com.hehe.Dao.Test_Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value = "/database")
public class Get_database {

    @Value("${spring.datasource.url}")
    private String datasource_url;

    @Autowired
    private Test_Mapper test_mapper;

    @GetMapping(value = "")
    @ResponseBody
    public String index(Model model) {
        String temp = "";
        String[] arr = datasource_url.split("\\?");
        arr=arr[0].split("3306/");
        String db_name = arr[1];

        System.out.println("spring.datasource.url  = " + datasource_url);
        temp = "CREATE DATABASE IF NOT EXISTS  " + db_name + "  DEFAULT CHARSET utf8 COLLATE utf8_general_ci; ";
        temp = datasource_url + "   <br><br>  " + temp;
        return "<h1>" + temp + "</h1>";
    }









}




